using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateCameraToOtherWindPos : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public Camera camera;
    public Transform tableCenter;

    public void RotateCameraToOtherWindPos1()
    {
        SetNewCameraTransforms(camera.transform, tableCenter);
    }
    
    public void SetNewCameraTransforms(
        Transform eastCamera, 
        Transform tableCenter)
    {
        if (eastCamera == null)
        {
            Debug.LogError("所有Transform参数都不能为空！");
            return;
        }

        Vector3 tableCenterPosition = tableCenter.position;

        // 1. 计算东风位摄像机相对于桌子中心的初始相对位置和旋转
        Vector3 relativePosEast = eastCamera.position - tableCenterPosition;
        Quaternion initialRotationEast = eastCamera.rotation;

        // 2. 计算并设置南风位摄像机
        Quaternion rotationSouth = Quaternion.AngleAxis(-90, Vector3.up);
        var position = tableCenterPosition + (rotationSouth * relativePosEast);
        var rotation = rotationSouth * initialRotationEast;

        eastCamera.position = position;
        eastCamera.rotation = rotation;

        // // 3. 计算并设置西风位摄像机
        // Quaternion rotationWest = Quaternion.AngleAxis(180, Vector3.up);
        // westCamera.position = tableCenterPosition + (rotationWest * relativePosEast);
        // westCamera.rotation = rotationWest * initialRotationEast;

        // // 4. 计算并设置北风位摄像机
        // Quaternion rotationNorth = Quaternion.AngleAxis(90, Vector3.up);
        // northCamera.position = tableCenterPosition + (rotationNorth * relativePosEast);
        // northCamera.rotation = rotationNorth * initialRotationEast;

        Debug.Log("南、西、北风位摄像机位置和旋转已更新。");
    }
}
